home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / lists / mint / l_0799 / 653 < prev    next >
Encoding:
Internet Message Format  |  1994-08-27  |  4.8 KB

  1. From: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
  2. Date: Mon, 15 Nov 93 11:09:23 +0100
  3. Message-Id: <9311151009.AA01444@issan.informatik.uni-dortmund.de>
  4. To: mint@atari.archive.umich.edu
  5. Subject: MiNT 1.09: make Frename/Fdelete succeed on readonly files
  6.  
  7. This patch removes the silly restriction that readonly files cannot be
  8. renamed or removed. Even on tosfs this will work now. The patch for
  9. tosfs.c also fixes a bug where the FA_DELETE flag (delete on close) is
  10. lost sometimes.
  11.  
  12. --- orig/dosdir.c    Mon Aug  2 18:57:34 1993
  13. +++ dosdir.c    Sat Nov 13 17:34:54 1993
  14. @@ -741,6 +741,7 @@
  15.          DEBUG(("Fdelete(%s): write access to directory denied",name));
  16.      } else {
  17.  /* BUG: we should check here for a read-only file */
  18. +/* No: this should depend on the file system */
  19.          r = (*dir.fs->remove)(&dir,temp1);
  20.      }
  21.      release_cookie(&dir);
  22. @@ -752,8 +753,11 @@
  23.      int junk;        /* ignored, for TOS compatibility */
  24.      const char *old, *new;
  25.  {
  26. -    fcookie olddir, newdir, oldfil;
  27. +    fcookie olddir, newdir;
  28. +#if 0
  29. +    fcookie oldfil;
  30.      XATTR xattr;
  31. +#endif
  32.      char temp1[PATH_MAX], temp2[PATH_MAX];
  33.      long r;
  34.  
  35. @@ -766,6 +770,9 @@
  36.          DEBUG(("Frename(%s,%s): error parsing old name",old,new));
  37.          return r;
  38.      }
  39. +
  40. +#if 0 /* this should depend on the file system */
  41. +
  42.  /* check for permissions on the old file
  43.   * GEMDOS doesn't allow rename if the file is FA_RDONLY
  44.   * we enforce this restriction only on regular files; processes,
  45. @@ -786,6 +793,8 @@
  46.          release_cookie(&olddir);
  47.          return EACCDN;
  48.      }
  49. +#endif
  50. +
  51.      r = path2cookie(new, temp1, &newdir);
  52.      if (r) {
  53.          DEBUG(("Frename(%s,%s): error parsing new name",old,new));
  54. @@ -800,6 +809,13 @@
  55.          return EXDEV;    /* cross device rename */
  56.      }
  57.  
  58. +    if (newdir.dev != olddir.dev) {
  59. +        DEBUG(("Frename(%s,%s): different devices",old,new));
  60. +        release_cookie(&olddir);
  61. +        release_cookie(&newdir);
  62. +        return EXDEV;    /* cross device rename */
  63. +    }
  64. +
  65.  /* check for write permission on both directories */
  66.      r = dir_access(&olddir, S_IWOTH);
  67.      if (!r) r = dir_access(&newdir, S_IWOTH);
  68. @@ -1042,6 +1058,13 @@
  69.          return EXDEV;    /* cross device link */
  70.      }
  71.  
  72. +    if (newdir.dev != olddir.dev) {
  73. +        DEBUG(("Flink(%s,%s): different devices",old,new));
  74. +        release_cookie(&olddir);
  75. +        release_cookie(&newdir);
  76. +        return EXDEV;    /* cross device link */
  77. +    }
  78. +
  79.  /* check for write permission on the destination directory */
  80.  
  81.      r = dir_access(&newdir, S_IWOTH);
  82. --- orig/tosfs.c    Fri Jun 25 22:24:32 1993
  83. +++ tosfs.c    Sat Nov 13 19:26:02 1993
  84. @@ -507,7 +507,7 @@
  85.          ti->size = foo.dta_size;
  86.          ti->date = foo.dta_date;
  87.          ti->time = foo.dta_time;
  88. -        ti->attr = foo.dta_attrib;
  89. +        ti->attr = foo.dta_attrib | (ti->attr & FA_DELETE);
  90.          if (executable_extension(foo.dta_name))
  91.              ti->attr |= FA_EXEC;
  92.          ti->valid = 1;
  93. @@ -560,7 +560,7 @@
  94.          ti->size = foo.dta_size;
  95.          ti->date = foo.dta_date;
  96.          ti->time = foo.dta_time;
  97. -        ti->attr = foo.dta_attrib;
  98. +        ti->attr = foo.dta_attrib | (ti->attr & FA_DELETE);
  99.          if (executable_extension(foo.dta_name))
  100.              ti->attr |= FA_EXEC;
  101.  around:
  102. @@ -672,19 +672,37 @@
  103.      const char *name;
  104.  {
  105.      struct tindex *ti;
  106. +    long r;
  107. +    int attr;
  108.  
  109.      (void)tfullpath(tmpbuf, (struct tindex *)dir->index, name);
  110.  
  111.      ti = tstrindex(tmpbuf);
  112.      if (ti->open) {
  113.          DEBUG(("tos_remove: file is open, will be deleted later"));
  114. -        if (ti->attr & FA_RDONLY)
  115. -            return EACCDN;
  116.          ti->attr |= FA_DELETE;
  117.          return 0;
  118.      }
  119. -    ti->valid = 0;
  120. -    return Fdelete(tmpbuf);
  121. +    r = Fdelete (tmpbuf);
  122. +    if (r == EACCDN)
  123. +      {
  124. +        if (ti->valid)
  125. +          attr = ti->attr;
  126. +        else
  127. +          {
  128. +        attr = Fattrib (tmpbuf, 0, 0);
  129. +        if (attr < 0)
  130. +          attr = 0;
  131. +          }
  132. +        if (attr & FA_RDONLY)
  133. +          {
  134. +        (void) Fattrib (tmpbuf, 1, attr & ~FA_RDONLY);
  135. +        r = Fdelete (tmpbuf);
  136. +        if (r < 0)
  137. +          (void) Fattrib (tmpbuf, 1, attr);
  138. +          }
  139. +      }
  140. +    return r;
  141.  }
  142.  
  143.  static long ARGS_ON_STACK 
  144. @@ -730,6 +748,19 @@
  145.      (void)tfullpath(tmpbuf, (struct tindex *)olddir->index, oldname);
  146.      (void)tfullpath(newbuf, (struct tindex *)newdir->index, newname);
  147.      r = Frename(0, tmpbuf, newbuf);
  148. +    if (r == EACCDN)
  149. +      {
  150. +        int attr = Fattrib (tmpbuf, 0, 0);
  151. +        if (attr >= 0 && attr & FA_RDONLY)
  152. +          {
  153. +        (void) Fattrib (tmpbuf, 1, attr & ~FA_RDONLY);
  154. +        r = Frename (0, tmpbuf, newbuf);
  155. +        if (r == 0)
  156. +          (void) Fattrib (newbuf, 1, attr);
  157. +        else
  158. +          (void) Fattrib (tmpbuf, 1, attr);
  159. +          }
  160. +      }
  161.      if (r == 0) {
  162.          ti = tstrindex(tmpbuf);
  163.          kfree(ti->name);
  164. @@ -1310,11 +1341,20 @@
  165.          r = Fclose((int)f->devinfo);
  166.  
  167.  /* if the file was marked for deletion, delete it */
  168. -        if (!t->open) {
  169. -            if (t->attr & FA_DELETE) {
  170. -                (void)Fdelete(t->name);
  171. -                t->name = 0;
  172. -            }
  173. +        if (!t->open && t->attr & FA_DELETE) {
  174. +            int attr;
  175. +            if (t->valid)
  176. +              attr = t->attr;
  177. +            else
  178. +              {
  179. +                attr = Fattrib (t->name, 0, 0);
  180. +                if (attr < 0)
  181. +                  attr = 0;
  182. +              }
  183. +            if (attr & FA_RDONLY)
  184. +              (void) Fattrib (t->name, 1, attr & ~FA_RDONLY);
  185. +            (void)Fdelete(t->name);
  186. +            t->name = 0;
  187.          }
  188.      }
  189.      return r;
  190.